<template>
  <div>
    <a-card title="广播信息配置">
      <!-- <a slot="extra" href="#" @click="showModal">详情</a> -->
      <a-table
        bordered
        :columns="columns"
        size="small"
        :showHeader="false"
        :data-source="data"
        :pagination="false"
      >
        <span slot="action" slot-scope="text,record">
          <a-button @click="handleShowInfo(record)">发送</a-button>
        </span>
      </a-table>
    </a-card>
    <!-- <a-modal v-model="visible" title="历史信息" @ok="handleOk" width="60%">
      <a-table :columns="columns" :data-source="dataHistory"></a-table>
    </a-modal>-->
  </div>
</template>

<script>
import { getAction } from '@/api/manage'
export default {
  name: "InfomationConfig",
  data() {
    const columns = [
      {
        title: '内容',
        dataIndex: 'text',
        key: 'text',
      },

      {
        title: '操作',
        dataIndex: 'action',
        // align: 'center',
        fixed: 'right',
        width: 220,
        scopedSlots: { customRender: 'action' },
      },
    ];
    const data = [
      {
        key: '0',
        text: '广播信息(地);',
        value: '1',
      },
    ];
    return {
      data,
      columns,
      visible: false,
      dataHistory: [],
      url: {
        list: '/KeyTrackingAreas',
        historyList: '/KeyTrackingAreas/historyList'
      }
    };
  },
  created() {
    // this.getList()
    let propsList = ['carname']
    propsList.map((item) => {
      this.data = [...this.changeData(this.data, item)]
    })
  },
  methods: {

    changeData(data, field) {
      let count = 0 //重复项的第一项
      let indexCount = 1 //下一项
      while (indexCount < data.length) {
        var item = data.slice(count, count + 1)[0] //获取没有比较的第一个对象
        if (!item[`${field}rowSpan`]) {
          item[`${field}rowSpan`] = 1 //初始化为1
        }
        if (item[field] === data[indexCount][field]) {
          //第一个对象与后面的对象相比，有相同项就累加，并且后面相同项设置为0
          item[`${field}rowSpan`]++
          data[indexCount][`${field}rowSpan`] = 0
        } else {
          count = indexCount
        }
        indexCount++
      }
      return data
    },
    getList() {
      getAction(this.url.list).then(res => {
        if (res.success) {
          this.data = res.result
        } else {
          this.$message.error(res.message)
        }
      })
    },

    showModal() {
      this.visible = true;
      getAction(this.url.historyList).then(res => {
        if (res.success) {
          this.dataHistory = res.result.records
        } else {
          this.$message.error(res.message)
        }
      })
    },
    handleOk(e) {
      console.log(e);
      this.visible = false;
    },
  }
}
</script>

<style>
</style>